import { defineComponent, computed } from '@vue-mini/wechat';
import { store } from '@/store';
import { addCart } from '@/store/action';
import { cartPrice, cartTotalPrice } from '@/store/getter';

defineComponent(() => {
  const goodsList = [
    { id: 1, name: '苹果', price: 2 },
    { id: 2, name: '香蕉', price: 3 },
  ];

  function onCartAdd(event) {
    const { item } = event.currentTarget.dataset;
    addCart(item);
  }

  return {
    goodsList,
    cartList: computed(() => store.cartList),
    cartPrice: computed(() => cartPrice()),
    cartTotalPrice: computed(() => cartTotalPrice()),
    onCartAdd,
  };
});
